<template>
  <!--新建问题-->
  <div class="ziliao">
    <wv-group title="问题名称">
      <wv-input placeholder="请输入问题标题" v-model="question.questionName" :required="true" :validate-mode="{onFocus: false, onBlur: true, onChange: false}"></wv-input>
    </wv-group>
    <wv-group title="问题描述">
      <wv-textarea placeholder="请输入问题描述" v-model="question.questionContent" show-counter max-length="500" required :validate-mode="{onFocus: false, onBlur: true, onChange: false}"></wv-textarea>
    </wv-group>
    <p class="offer" @click="goSubmitQuestion(question)">提交</p>
  </div>
</template>

<script type="text/ecmascript-6">
  import {addQuestion} from '../../../../test/unit/http'
  import {Toast} from 'we-vue'
  export default {
    name: '',
    props: {},
    data() {
      return {
        question: {}
      };
    },
    methods: {
      checkFrom(question){
        var msg = {};
        if (this.$myUtils.isNull(question.questionName)) {
          msg['result'] = false;
          msg['info'] = '请输入问题标题';
          return msg;
        }
        if (this.$myUtils.isNull(question.questionContent)) {
          msg['result'] = false;
          msg['info'] = '请输入问题描述';
          return msg;
        }
        msg['result'] = true;
        msg['info'] = '校验成功';
        return msg;
      },
      goSubmitQuestion(question){
        var checkResult = this.checkFrom(question);
        if (!checkResult.result) {
          Toast.text(checkResult.info);
          return;
        }
        addQuestion(question).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.$router.back(-1)
          } else {
            Toast.fail(res.info);
          }
        });
      }
    },
    created() {

    },
    components: {}
  }
</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .offer {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-image: linear-gradient(to left, #4c92ed, #61beec);
    height: 50px;
    line-height: 50px;
    color: #fff;
  }
</style>
